<?php

namespace plugins\module_config\controller;

use app\common\lib\file_operate\FileOperate; //引入此类
use cmf\controller\PluginAdminBaseController;
//文件操作类

class AdminIndexController extends PluginAdminBaseController
{
    protected function _initialize()
    {
        parent::_initialize();
        $adminId = cmf_get_current_admin_id(); //获取后台管理员id，可判断是否登录
        if (!empty($adminId)) {
            $this->assign("admin_id", $adminId);
        }
    }

    public function index()
    {
        $visiConfig = new \plugins\module_config\controller\ModuleListController();

        return $visiConfig->index();
    }

    /**
     * 上传图片
     */
    public function upload()
    {
        $data = $this->request->param();

        if (empty($_FILES)) {
            return api_json_echo(false, '非法上传内容！', null, 110);
        }

        $file = $_FILES['file'];

        $app = $data['app'];

        $upload_path = "/plugins/" . $app . "/view/public/assets/images/default";

        $res = uploadImg($file, $upload_path);

        if ($res['status'] != true) {
            return api_json_echo(false, '上传失败', $res['message'], $res['code']);
        }

        return api_json_echo(true, '上传成功', $res['data'], 200);
    }

}
